<template>
	<view class="my-page">
		<u-navbar title="变更密码" bgColor="rgba(255,255,255,0.0)" :auto-back="true" :placeholder="true"></u-navbar>
		<view class="content">
			<view class="title">
				新密码
			</view>
			<view class="text">
				<u--input placeholder="请输入新密码" border="none" v-model="password"></u--input>
			</view>
			<view class="title">
				验证码
			</view>
			<view class="text">
				<u-input placeholder="请输入谷歌验证码或手机验证码" border="none" v-model="alipay_code">
					<template slot="suffix">
						<u-code ref="uCode" @change="codeChange" seconds="60" changeText="X秒重新获取"></u-code>
						<u-button @tap="getCode" :text="tips" type="success"
							color="linear-gradient(90deg, rgb(254, 138, 3) 0%, rgb(250, 89, 0) 100%)"
							size="mini"></u-button>
					</template>
				</u-input>
			</view>
			<view class="pay-btn">
				<u-button type="primary" text="提交" shape="circle" @click="goup"
					color="linear-gradient(90deg, rgb(254, 138, 3) 0%, rgb(250, 89, 0) 100%)"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				password:'',
				alipay_code:'',
				tips: '',
			}
		},
		methods:{
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					// 模拟向后端请求验证码
					uni.showLoading({
						title: '正在获取验证码'
					})
					setTimeout(() => {
						uni.hideLoading();
						// 这里此提示会被this.start()方法中的提示覆盖
						uni.$u.toast('验证码已发送');
						// 通知验证码组件内部开始倒计时
						this.$refs.uCode.start();
					}, 2000);
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			goup(){
				if (this.password == '') {
					uni.showToast({
						title: '新密码不能为空！',
						icon: 'none'
					})
					return
				}
				let params = {
					newPassword: this.password,
					googleSms:this.alipay_code
				}
				uni.showLoading({
					mask: true
				})
				this.$Request({
					method: 'POST',
					url: '/api/member/user/changePassword',
					data: params,
					ismsg: true,
				}).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.password = ''
						this.alipay_code = ''
						setTimeout(()=>{
							uni.navigateBack({
								delta: 1,
							});
						},1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.my-page {
		min-height: calc(100vh - 91rpx);
		background-image: url('../../../../static/goods/top-bg.png');
		background-size: 100% 561rpx;
		background-repeat: no-repeat;

		.content {
			padding: 0 30rpx;
			.pay-btn {
				margin-top: 60rpx;
			}
			
			.title {
				font-size: 28rpx;
				color: #333333;
				font-weight: bold;
				margin-top: 20rpx;
			}
			
			.text {
				background-color: #ffffff;
				box-shadow: 0rpx 0rpx 16rpx 1rpx rgba(0, 0, 0, 0.08);
				padding: 20rpx 30rpx;
				margin-top: 20rpx;
				border-radius: 20rpx;
			}
			.code {
				width: 100%;
				height: 600rpx;
				background-color: #ffffff;
				box-shadow: 0rpx 0rpx 16rpx 1rpx rgba(0, 0, 0, 0.08);
				margin-top: 30rpx;
				padding: 20rpx;
				border-radius: 20rpx;
				display: flex;
				justify-content: center;
			
				image {
					width: 500rpx;
					height: 500rpx;
					margin-top: 5%;
				}
			}
		}
	}
</style>